package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.StudentLossItem;
import cn.wolfcode.crm.mapper.StudentLossItemMapper;
import cn.wolfcode.crm.query.StudentLossItemQueryObj;
import cn.wolfcode.crm.service.IStudentLossItemService;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentLossItemServiceImpl implements IStudentLossItemService {

    @Autowired
    private StudentLossItemMapper studentLossItemMapper;

    public void delete(Long id) {
        if(id!=null){
            studentLossItemMapper.deleteByPrimaryKey(id);
        }
    }

    public void save(StudentLossItem entity) {
        if(entity!=null){
            studentLossItemMapper.insert(entity);
        }
    }

    public void update(StudentLossItem entity) {
        if(entity!=null){
            studentLossItemMapper.updateByPrimaryKey(entity);
        }
    }

    public StudentLossItem get(Long id) {
        return studentLossItemMapper.selectByPrimaryKey(id);
    }

    public List<StudentLossItem> list() {
        return studentLossItemMapper.selectAll();
    }

    public PageResult query(StudentLossItemQueryObj qo) {
        //查总数
        int total = studentLossItemMapper.queryForCount(qo);
        if(total == 0){
            return new PageResult();
        }
        //查数据
        List<StudentLossItem> rows = studentLossItemMapper.queryForList(qo);
        return new PageResult(total, rows);
    }

    public void audit(Long id) {
        if(id!=null){
            //修改审核状态
            studentLossItemMapper.updateAuditState(id);
            //设置审核人员
            Employee emp = (Employee) SecurityUtils.getSubject().getPrincipal();
            studentLossItemMapper.updateAuditUser(emp.getId(),id);

        }
    }
}
